import re


def remove_think_blocks(text: str) -> str:
    # 使用正则表达式替换所有<think>...</think>及其内容为空字符串
    pattern = r'<think>.*?</think>'
    return re.sub(pattern, '', text, flags=re.DOTALL)


def remove_md_go_code_blocks(text: str) -> str:
    # 匹配 ```go ... ``` 代码块（含换行）
    pattern = r'```go\b[^\S\r\n]*[\s\S]*?```'
    return re.sub(pattern, '', text)


def extract_md_go_code_blocks(text) -> str:
    # 匹配 ```go ... ``` 并提取其中的代码
    pattern = r'```go\b[^\S\r\n]*(.*?)```'
    matches = re.findall(pattern, text, flags=re.DOTALL)
    if len(matches) > 0:
        return matches[0]
    return ""
